from django.shortcuts import render
from rest_framework import viewsets

# Create your views here.
from .models import WeldDefects,WeldTask,WeldVideo
from .serializers import WeldVideoSerializer,WeldTaskerializer,WeldDefectsSerializer

class WeldTaskViewSet(viewsets.ModelViewSet):
    queryset = WeldTask.objects.order_by("-id")
    serializer_class = WeldTaskerializer
    search_fields = [
        "project_number",
        "tube_number",
        "part_name",
    ]
    filterset_fields = {
        "project_number": ["icontains"],
        "tube_number": ["icontains"],
        "part_name": ["icontains"],
        "inspector": ["exact"],
        "inspect_date": ["gte", "lte"],
        "reviewer": ["exact"],
        "review_date": ["gte", "lte"],
    }
    
class WeldVideoViewSet(viewsets.ModelViewSet):
    def get_queryset(self):
        return WeldVideo.objects.filter(project=self.kwargs["weldtask_pk"]).order_by(
            "-id"
        )

    serializer_class = WeldVideoSerializer
    search_fields = ["note", "video_number", "evaluation", "weld_length", "velocity"]
    filterset_fields = {
        # "examined_area_number": ["exact", "icontains"],
        # "film_density": ["gte", "lte"],
        # "film_number": ["exact", "icontains"],
    }
    
    

class WeldDefectViewSet(viewsets.ModelViewSet):
    def get_queryset(self):
        return WeldDefects.objects.filter(video=self.kwargs["video_pk"]).order_by(
            "id"
        )
        
    serializer_class = WeldDefectsSerializer
    search_fields = ["kind","note","x","y","frame_number"]
    filterset_fields = {
        "kind": ["exact", "icontains"],
        # "grade": ["gte", "lte"],
        "x": ["gte", "lte"],
        "y": ["gte", "lte"],
        "frame_number": ["gte", "lte"],
    }